|
1
|
|
|
var assert = require('chai').assert, |
|
2
|
|
|
GedcomX = require('../'); |
|
3
|
|
|
|
|
4
|
|
|
describe('NamePart', function(){ |
|
5
|
|
|
|
|
6
|
|
|
it('Create plain', function(){ |
|
7
|
|
|
var newNamePart = new GedcomX.NamePart(), |
|
8
|
|
|
part = GedcomX.NamePart(); |
|
9
|
|
|
assert.instanceOf(newNamePart, GedcomX.NamePart, 'An instance of NamePart is not returned when calling the constructor with new.'); |
|
10
|
|
|
assert.instanceOf(part, GedcomX.NamePart, 'An instance of NamePart is not returned when calling the constructor without new.'); |
|
11
|
|
|
}); |
|
12
|
|
|
|
|
13
|
|
|
it('Create with JSON', function(){ |
|
14
|
|
|
var part = GedcomX.NamePart({ |
|
15
|
|
|
id: 'namepart', |
|
16
|
|
|
type: 'http://gedcomx.org/Given', |
|
17
|
|
|
value: 'Jonathan', |
|
18
|
|
|
qualifiers: [ |
|
19
|
|
|
{ |
|
20
|
|
|
name: 'http://gedcomx.org/Primary' |
|
21
|
|
|
} |
|
22
|
|
|
] |
|
23
|
|
|
}); |
|
24
|
|
|
assert.equal(part.getId(), 'namepart'); |
|
25
|
|
|
assert.equal(part.getType(), 'http://gedcomx.org/Given'); |
|
26
|
|
|
assert.equal(part.getValue(), 'Jonathan'); |
|
27
|
|
|
assert.equal(part.getQualifiers().length, 1); |
|
28
|
|
|
assert.equal(part.getQualifiers()[0].getName(), 'http://gedcomx.org/Primary'); |
|
29
|
|
|
}); |
|
30
|
|
|
|
|
31
|
|
|
it('Create with mixed data', function(){ |
|
32
|
|
|
var part = GedcomX.NamePart({ |
|
33
|
|
|
id: 'namepart', |
|
34
|
|
|
type: 'http://gedcomx.org/Given', |
|
35
|
|
|
value: 'Jonathan', |
|
36
|
|
|
qualifiers: [ |
|
37
|
|
|
GedcomX.Qualifier({ |
|
38
|
|
|
name: 'http://gedcomx.org/Primary' |
|
39
|
|
|
}) |
|
40
|
|
|
] |
|
41
|
|
|
}); |
|
42
|
|
|
assert.equal(part.getId(), 'namepart'); |
|
43
|
|
|
assert.equal(part.getType(), 'http://gedcomx.org/Given'); |
|
44
|
|
|
assert.equal(part.getValue(), 'Jonathan'); |
|
45
|
|
|
assert.equal(part.getQualifiers().length, 1); |
|
46
|
|
|
assert.equal(part.getQualifiers()[0].getName(), 'http://gedcomx.org/Primary'); |
|
47
|
|
|
}); |
|
48
|
|
|
|
|
49
|
|
|
it('Build', function(){ |
|
50
|
|
|
var part = GedcomX.NamePart() |
|
51
|
|
|
.setId('namepart') |
|
52
|
|
|
.setType('http://gedcomx.org/Given') |
|
53
|
|
|
.setValue('Jonathan') |
|
54
|
|
|
.addQualifier(GedcomX.Qualifier().setName('http://gedcomx.org/Primary')); |
|
55
|
|
|
assert.equal(part.getId(), 'namepart'); |
|
56
|
|
|
assert.equal(part.getType(), 'http://gedcomx.org/Given'); |
|
57
|
|
|
assert.equal(part.getValue(), 'Jonathan'); |
|
58
|
|
|
assert.equal(part.getQualifiers().length, 1); |
|
59
|
|
|
assert.equal(part.getQualifiers()[0].getName(), 'http://gedcomx.org/Primary'); |
|
60
|
|
|
}); |
|
61
|
|
|
|
|
62
|
|
|
it('toJSON', function(){ |
|
63
|
|
|
var data = { |
|
64
|
|
|
id: 'namepart', |
|
65
|
|
|
type: 'http://gedcomx.org/Given', |
|
66
|
|
|
value: 'Jonathan', |
|
67
|
|
|
qualifiers: [ |
|
68
|
|
|
{ |
|
69
|
|
|
name: 'http://gedcomx.org/Primary' |
|
70
|
|
|
} |
|
71
|
|
|
] |
|
72
|
|
|
}, part = GedcomX.NamePart(data); |
|
73
|
|
|
assert.deepEqual(part.toJSON(), data); |
|
74
|
|
|
}); |
|
75
|
|
|
|
|
76
|
|
|
it('constructor does not copy instances', function(){ |
|
77
|
|
|
var obj1 = GedcomX.NamePart(); |
|
78
|
|
|
var obj2 = GedcomX.NamePart(obj1); |
|
79
|
|
|
assert.strictEqual(obj1, obj2); |
|
80
|
|
|
}); |
|
81
|
|
|
|
|
82
|
|
|
}); |